package com.github.chirspan.xaas.soa.message.processor;

import com.github.chirspan.xaas.soa.message.core.MessageModel;
import com.github.chirspan.xaas.soa.message.core.SOAMessage;
import com.github.chirspan.xaas.soa.message.schema.MessageSchemaDefinition;
import lombok.extern.slf4j.Slf4j;

import java.io.PrintWriter;
import java.io.StringWriter;

@Slf4j
public abstract class AbstractMessageProcessor implements IMessageProcessor {

    @Override
    public abstract String getMessageType();

    @Override
    public abstract SOAMessage generate(MessageModel model,
                                        MessageSchemaDefinition msd);

    @Override
    public abstract MessageModel parse(SOAMessage soaMessage) throws Exception;


    public static String getStackTrace(Throwable e) {
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        e.printStackTrace(pw);
        pw.close();
        return sw.toString();
    }
}
